// Tags: 
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 100;
int sn, tn, cnt;
char s[N], t[N], tmp[N];
std::vector<int> vec[26];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("I.in", "r", stdin);
  freopen("I.out", "w", stdout);
#endif
#endif

  while (scanf("%s%s", s + 1, t + 1) != EOF) {
    sn = strlen(s + 1), tn = strlen(t + 1);
    for (int i = 0; i < 26; ++i) vec[i].clear();
    for (int i = 1; i <= tn; ++i) {
      vec[t[i] - 'a'].emplace_back(i);
    }
    int ans = 0;
    for (int i = 1; i <= tn; ++i) {
      cnt = 0;
      for (int j = 25; ~j; --j) {
        if (vec[j].empty()) continue;
        auto iter = vec[j].begin();
        int i = 0;
        while (*iter > i && iter != vec[j].end()) {
          tmp[++cnt] = 'a' + j;
          ++iter;
        }
      }
    }
  }
  return 0;
}